//
//  ViewControllerForWoDe.m
//  SeeTheWorld
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewControllerForWoDe.h"
#import "PCH.pch"
#import "TeHui.h"
#import "WoDeHaoYou.h"
#import "QingDan.h"
#import "ShouCang.h"
#import "VCOfDengLu.h"
#import <UIImageView+WebCache.h>


@interface ViewControllerForWoDe () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)UIButton *buttonOfDengLu;
@property (nonatomic, retain)UILabel *label;
@property (nonatomic, retain)NSMutableArray *arrayOfTitle;
@property (nonatomic, retain)NSMutableArray *arrayOfTuBiao;
@property (nonatomic, retain)UIImageView *imageOfTouXiang;

@property (nonatomic, assign)CGFloat top;
@property (nonatomic, retain)UIView *shadow;

@end

@implementation ViewControllerForWoDe

- (void)dealloc {
    self.tableView.delegate = nil;
    self.tableView.dataSource = nil;
    [_imageOfTouXiang release];
    [_shadow release];
    [_arrayOfTitle release];
    [_buttonOfDengLu release];
    [_label release];
    [_tableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"个人中心";
    self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:19], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName,nil];
    
    [self handleData];
    
    [self createTableView];
    
    
}

#pragma mark - 创建视图
- (void)createTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    [_tableView release];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.tableView.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"pool"];
    
    self.tableView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -200, [UIScreen mainScreen].bounds.size.width, 200)];
    
    imageView.image = [UIImage imageNamed:@"22"];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.tag = 101;
    [self.tableView addSubview:imageView];
    imageView.userInteractionEnabled = YES;
    
    UILabel *labelOfHello = [[UILabel alloc] initWithFrame:CGRectMake(50, imageView.frame.size.height / 2 + 20, WIDTH - 100, 40)];
    [imageView addSubview:labelOfHello];
    [labelOfHello release];
    labelOfHello.textAlignment = 1;
    
    NSString *originStr = @"SeeTheWorld";
    NSMutableAttributedString *attributedStr01 = [[NSMutableAttributedString alloc] initWithString: originStr];
    [attributedStr01 addAttribute: NSFontAttributeName value: [UIFont fontWithName: @"Zapfino" size: 20] range:NSMakeRange(0, originStr.length)];
    [attributedStr01 addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range: NSMakeRange(0, 4)];
    [attributedStr01 addAttribute: NSForegroundColorAttributeName value: [UIColor greenColor] range: NSMakeRange(4, 3)];
    [attributedStr01 addAttribute:NSStrokeWidthAttributeName value:@(-5) range:NSMakeRange(0, originStr.length)];
    labelOfHello.attributedText = attributedStr01;
    
//    self.buttonOfDengLu = [UIButton buttonWithType:UIButtonTypeCustom];
//    [imageView addSubview:self.buttonOfDengLu];
//    [self.buttonOfDengLu setTitle:@"点击登录" forState:UIControlStateNormal];
//    self.buttonOfDengLu.frame = CGRectMake(WIDTH / 5 - 10 + WIDTH / 5 + 10, imageView.frame.size.height / 2 + WIDTH / 5 / 3, WIDTH / 4, 30);
//    
//    self.imageOfTouXiang = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wodetouxiang"]];
//    self.imageOfTouXiang.frame = CGRectMake(WIDTH / 5 - 10, imageView.frame.size.height / 2, WIDTH / 5, WIDTH / 5);
//    [imageView addSubview:self.imageOfTouXiang];
//    [_imageOfTouXiang release];
//    self.imageOfTouXiang.backgroundColor = [UIColor colorWithRed:148 / 256.f green:231 / 256.f blue:237 / 256.f alpha:1];
//    self.imageOfTouXiang.layer.cornerRadius = WIDTH / 5 / 2;
//    self.imageOfTouXiang.layer.masksToBounds = YES;
//    self.imageOfTouXiang.userInteractionEnabled = YES;
   
    
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(5, imageView.frame.size.height - 20, WIDTH - 10, 30)];
    [imageView addSubview:self.label];
    [_label release];
    self.label.text = @"专业行程规划师, 精品美图, 在线等您";
    self.label.textColor = [UIColor whiteColor];
    self.label.textAlignment = 1;
    self.label.font = [UIFont systemFontOfSize:18];
    
}


#pragma mark - 数据
- (void)handleData {
    
    self.arrayOfTitle = @[@"旅行清单", @"我的好友", @"收藏", @"特惠"].mutableCopy;
    self.arrayOfTuBiao = @[@"LvXingQingDan", @"WoDeHaoYou", @"ShouCang",@"TeHui"].mutableCopy;
    
}

/** 背景照片滑动 */
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGPoint point = scrollView.contentOffset;
    if (point.y < -200) {
        CGRect rect = [self.tableView viewWithTag:101].frame;
        rect.origin.y = point.y;
        rect.size.height = -point.y;
        [self.tableView viewWithTag:101].frame = rect;
}
    
}

/** 返回分区数 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

/** 返回区头高度 */
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 20;
}

/** 返回行高 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

/** 返回行数 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.arrayOfTitle.count;
}

/** 返回cell */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    
    cell.textLabel.text = [self.arrayOfTitle objectAtIndex:indexPath.row];
    cell.imageView.image = [UIImage imageNamed:[self.arrayOfTuBiao objectAtIndex:indexPath.row]];
    cell.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
    cell.textLabel.dk_textColorPicker = DKColorWithRGB(0x343434, 0xffffff);
    return cell;
}

#pragma mark - 选中cell跳转下一界面
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
     if (indexPath.row == 3) {
        TeHui *vc = [[TeHui alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    } else if (indexPath.row == 1) {
        WoDeHaoYou *vc = [[WoDeHaoYou alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    } else if (indexPath.row == 0) {
        QingDan *vc = [[QingDan alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    } else if (indexPath.row == 2) {
        ShouCang *vc = [[ShouCang alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    }
    
}

/** 视图将要出现. */
- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBar.dk_barTintColorPicker = DKColorWithColors([UIColor colorWithRed:43 / 256.f green:115 / 256.f blue:217 / 256.f alpha:1], [UIColor colorWithRed:39 / 256.f green:39 / 256.f blue:39 / 256.f alpha:1]);
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"夜间模式"]) {
        
        [DKNightVersionManager nightFalling];
        
    } else {
        
        [DKNightVersionManager dawnComing];
    }
    
    [self.tableView reloadData];
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
